{
    "nbformat": 4,
    "nbformat_minor": 2,
    "metadata": {
        "language_info": {
            "name": "python",
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "version": "3.8.1-final"
        },
        "orig_nbformat": 2,
        "file_extension": ".py",
        "mimetype": "text/x-python",
        "name": "python",
        "npconvert_exporter": "python",
        "pygments_lexer": "ipython3",
        "version": 3
    },
    "cells": [
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "## Intall pythreejs\n",
                "pip install pythreejs"
            ],
            "execution_count": null,
            "outputs": []
        },
        {
            "cell_type": "code",
            "execution_count": 11,
            "metadata": {},
            "outputs": [],
            "source": [
                "from pythreejs import *\n",
                "from IPython.display import display\n",
                "from math import pi\n",
                ""
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 12,
            "metadata": {},
            "outputs": [],
            "source": [
                "# Reduce repo churn for examples with embedded state:\n",
                "from pythreejs._example_helper import use_example_model_ids\n",
                "use_example_model_ids()"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 13,
            "metadata": {},
            "outputs": [],
            "source": [
                "BoxGeometry(\n",
                "    width=5,\n",
                "    height=10,\n",
                "    depth=15,\n",
                "    widthSegments=5,\n",
                "    heightSegments=10,\n",
                "    depthSegments=15)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 14,
            "metadata": {},
            "outputs": [],
            "source": [
                "view_width = 600\n",
                "view_height = 400"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 15,
            "metadata": {},
            "outputs": [],
            "source": [
                "sphere = Mesh(\n",
                "    SphereBufferGeometry(1, 32, 16),\n",
                "    MeshStandardMaterial(color='red')\n",
                ")"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 16,
            "metadata": {},
            "outputs": [],
            "source": [
                "cube = Mesh(\n",
                "    BoxBufferGeometry(1, 1, 1),\n",
                "    MeshPhysicalMaterial(color='green'),\n",
                "    position=[2, 0, 4]\n",
                ")\n",
                ""
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 17,
            "metadata": {},
            "outputs": [],
            "source": [
                "camera = PerspectiveCamera( position=[10, 6, 10], aspect=view_width/view_height)\n",
                "key_light = DirectionalLight(position=[0, 10, 10])\n",
                "ambient_light = AmbientLight()"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 18,
            "metadata": {},
            "outputs": [
            ],
            "source": [
                "f = \"\"\"\n",
                "function f(origu, origv, out) {\n",
                "    // scale u and v to the ranges I want: [0, 2*pi]\n",
                "    var u = 2*Math.PI*origu;\n",
                "    var v = 2*Math.PI*origv;\n",
                "\n",
                "    var x = Math.sin(u);\n",
                "    var y = Math.cos(v);\n",
                "    var z = Math.cos(u+v);\n",
                "\n",
                "    out.set(x,y,z)\n",
                "}\n",
                "\"\"\"\n",
                "surf_g = ParametricGeometry(func=f, slices=16, stacks=16);\n",
                "\n",
                "surf1 = Mesh(geometry=surf_g,\n",
                "             material=MeshLambertMaterial(color='green', side='FrontSide'))\n",
                "surf2 = Mesh(geometry=surf_g,\n",
                "             material=MeshLambertMaterial(color='yellow', side='BackSide'))\n",
                "surf = Group(children=[surf1, surf2])\n",
                "\n",
                "camera2 = PerspectiveCamera( position=[10, 6, 10], aspect=view_width/view_height)\n",
                "scene2 = Scene(children=[surf, camera2,\n",
                "                         DirectionalLight(position=[3, 5, 1], intensity=0.6),\n",
                "                         AmbientLight(intensity=0.5)])\n",
                "renderer2 = Renderer(camera=camera2, scene=scene2,\n",
                "                     controls=[OrbitControls(controlling=camera2)],\n",
                "                     width=view_width, height=view_height)\n",
                "display(renderer2)"
            ]
        }
    ]
}
